#include <stdio.h>
#include <pthread.h>
#include <unistd.h>

void* Routine (void* arg)
{
    pthread_detach(pthread_self());
    printf("%s detach success!\n");
    int cnt=0;
    while(cnt<5)
    {
        cnt++;
        printf("%s running...\n",(char*)arg);
        sleep(1);
    }
    printf("%s return...\n");
    return NULL;
}

int main()
{
    pthread_t tid;
    pthread_create(&tid,NULL,Routine,(void*)"thread");
    
    sleep(2);//等待线程分离

    void* ret;
    if(pthread_join(tid,&ret)==0)
        printf("thread join success! ret:%d\n",(int*)ret);
    else 
        printf("thread join fail... ret:%d\n",(int*)ret);
    return 0;
}
